<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="myBtn" onclick="handleClick()">btn</div>
    <script>
        let btn = document.getElementById("btn")
        //创建event对象
        let event = document.createEvent("MouseEvent")
        //初始化
        event.initEvent("click")
        //触发
        btn.dispatchEvent(event)
        function handleClick() {
            alert('click')
        }
    </script>
</body>

</html>